/**
 * @file filter
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  PureComponent,
  PropTypes
} from 'react';
import {Renderer} from '../../renderer';

@Renderer({
  name: 'field-status',
  desc: '...',
  test: /(?:^|\/)field\/status$/
})
export default class StatusField extends PureComponent {
  static propTypes = {
    className: PropTypes.string,
    type: PropTypes.string.isRequired
  };

  makeClassName(value) {
    const map = [
      'fa fa-times text-danger',
      'fa fa-check text-success'
    ];

    if (typeof value === 'boolean') {
      value = value ? 1 : 0;
    } else {
      value = parseInt(value, 10) || 0;
    }

    return map[value % map.length];
  }

  render() {
    const {
      className,
      value
    } = this.props;

    return (
      <div className={className}>
        <i className={this.makeClassName(value)} />
      </div>
    );
  }
}
